<!--
 * @Author: your name
 * @Date: 2021-03-31 20:39:00
 * @LastEditTime: 2021-04-15 16:45:13
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \web\node\views\back\sowing_add.html
-->
<!-- 继承base基础模板 -->
{%  extends "back/base.html" %}

<!-- 留槽 样式 -->
{% block style %}
{% endblock %}

 <!-- 留槽 主要内容 -->
{% block body %}
    <div class="container-fluid">
    <div class="body advert">
        <!-- 面包屑 -->
        <ol class="breadcrumb">
            <li><a href="s_list">轮播图管理</a></li>
            <li class="active">添加轮播图</li>
        </ol>
        <div class="advert-add">
            <form action="/back/sowing/api/add" method="post" class="form-horizontal" enctype="multipart/form-data">
                <div class="form-group">
                    <label for="" class="col-md-3 control-label">轮播图名称</label>
                    <div class="col-md-5">
                        <input name="image_title" type="text" class="form-control input-sm" placeholder="填写轮播图名称" required>
                    </div>
                </div>
                <div class="form-group">
                    <label for="" class="col-md-3 control-label">轮播图链接</label>
                    <div class="col-md-5">
                        <input name="image_url" type="file" class="form-control input-sm" required>
                    </div>
                </div>
                <div class="form-group">
                    <label for="" class="col-md-3 control-label">跳转链接</label>
                    <div class="col-md-5">
                        <input name="image_link" type="text" class="form-control input-sm" placeholder="填写跳转链接" required>
                    </div>
                </div>
                <div class="form-group">
                    <label for="" class="col-md-3 control-label">上架时间</label>
                    <div class="col-md-5">
                        <input name="s_time" type="date" class="form-control input-sm" required>
                    </div>
                </div>
                <div class="form-group">
                    <label for="" class="col-md-3 control-label">下架时间</label>
                    <div class="col-md-5">
                        <input name="e_time" type="date" class="form-control input-sm" required>
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-md-8">
                        <input type="submit"  class="btn btn-danger btn-sm pull-right" value="添加文章"></input>
                    </div>                          
                </div>
            </form>
        </div>
    </div>
    </div>
{% endblock %}

   <!-- 留槽 脚本 -->
{% block script %}
    <script>
        // 1. 添加一条记录
      $('form').on('submit', function () {
          $.ajax({
              url: $(this).attr('action'),
              type:$(this).attr('method'),
              data: new FormData($(this)[0]),
              processData:false,
              contentType:false,
              success: function (data) {
                  console.log(data);
                  if(data.status === 200){ // 添加成功
                      alert('轮播图添加成功!');
                      window.location.href = '/back/s_list'
                  }else {
                      alert('轮播图添加失败!');
                  }
              }
          });
          // 阻止默认提交的事件
          return false;
      });
    </script>
{% endblock %}